<!-- This page asks for the location the students earned their degree
     from. They can choose from a list of U.S. States or countries, 
     which are displayed in a 3-column format. 
     
     Upon clicking submit, they are led to the Provide Degrees -- Choose
     University Page. -->

<%@page import="support.*, java.util.*" %>
<%@page import="support.*, java.util.*, java.sql.*, javax.sql.*" %>
<%@ taglib uri="http://struts.apache.org/tags-html" prefix="html" %> 
<%@ taglib uri="http://struts.apache.org/tags-bean" prefix="bean"%>
<%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic" %>

<%@ 
	page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"
%>

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Provide Degrees -- Choose Location</title>
</head>
<body>

<CENTER>
<h1> Graduate School Application </h1>
<h2> Provide Degrees -- Choose Location Page </h2>
</CENTER>

<!-- Display data collected from previous pages. -->

<b>First Name:</b> <bean:write name="studentsinfoform" property="first" />
<span style="padding-left:20px"><b>Middle Initial:</b> <bean:write name="studentsinfoform" property="middle" /></span>
<span style="padding-left:20px"><b>Last Name:</b>  <bean:write name="studentsinfoform" property="last" /> </span>
<p>
<b>Country of Citizenship:</b> <bean:write name="citizenshipform" property="citizen" /> <p>
<b>Country of Residence:</b> <bean:write name="residenceform" property="residence"/> <p>
<b>Country of Residency:</b> <bean:write name="residencyform" property="residency"/> <p>


<b>Address:</b><p>

	<logic:present name="addressform" property="street">
			<span style="padding-left:20px"><b>Street:</b> <bean:write name="addressform" property="street" /> <p></span>
	</logic:present>
	<logic:present name="addressform" property="city">
			<span style="padding-left:20px"><b>City:</b> <bean:write name="addressform" property="city" /> </span>
	</logic:present>	
	<logic:present name="addressform" property="lstate">
		<logic:notEqual  name="addressform" property="lstate" value="">
			<span style="padding-left:20px"><b>State:</b> <bean:write name="addressform" property="lstate" /> </span>
		</logic:notEqual>
	</logic:present>
	<logic:present name="addressform" property="zip">
		<logic:notEqual  name="addressform" property="zip" value="">
			<span style="padding-left:20px"><b>Zip Code:</b> <bean:write name="addressform" property="zip" /> </span>
		</logic:notEqual>
	</logic:present>
	<p>
	<b>Phone Number:</b> (<bean:write name="addressform" property="areaCode" />) 
	                     (<bean:write name="addressform" property="pnumber" />) <p>

<logic:notEqual name="degreeform" property="count" value="first">
<logic:iterate id="degreeId" name="degreeform" property="degrees" >
==========================================================
<p><b>Location:</b> <bean:write name="degreeId" property="stuState"/></p>
<p><b>School:</b> <bean:write name="degreeId" property="school"/></p>
<p><b>Discipline of degree:</b> <bean:write name="degreeId" property="discp"/>
						 <bean:write name="degreeId" property="title"/></p>
<p><b>Degree earned in:</b> <bean:write name="degreeId" property="dmonth"/>
					 <bean:write name="degreeId" property="dyear"/></p>
<p><b>GPA: </b><bean:write name="degreeId" property="gpa"/></p>
<p><b>Transcript: </b><bean:write name="degreeId" property="fileName"/></p>
</logic:iterate>
</logic:notEqual>
<!-- End of displaying collected information. -->

<br><b>Please specify the location you earned your degree(s) in.</b> <p>


<%
  support s = new support();   	
  String path1 = config.getServletContext().getRealPath("countries.txt");
  String path2 = config.getServletContext().getRealPath("universities.txt");
  String stuState = "";

  //getUniversities returns a vector of vectors where each vector is a tuple of <string, vector>
  //with the string being the name of the country/state and the vector being the list of universities there
  
    Vector universitiescpy = s.getUniversities(path2);
    universitiescpy.setSize(51);
    int ssize = universitiescpy.size()/3;
    int sleftover = universitiescpy.size()%3;

%>  
    <br>States in the United States:    
	<TABLE BORDER CELLSPACING=1 CELLPADDING=5>
	<TR>
<%    
    // print universities in 3-column format
    for (int i=0; i<universitiescpy.size()/3+1; i++)
    {       
        if(i == sleftover+ssize)
        {
         	 break;
         }
        Vector tuple = (Vector)universitiescpy.get(i);
        String state1 = (String)tuple.get(0);
        
        %>
    	  <TD>    	  
    	  	<html:link action="/degreeLoc">
			<html:param name="stuState" value='<%= state1 %>'/> <%= state1 %>
			</html:link>
    	  </TD>
    	  
        <%
        
        if(i+ sleftover+ssize == sleftover+ssize*2)
        {
      	  break;
        }
        tuple = (Vector)universitiescpy.get(i+ sleftover+ssize);
        String state2 = (String)tuple.get(0);
        %>
    	  <TD>
			<html:link action="/degreeLoc">
			<html:param name="stuState" value='<%= state2 %>'/> <%= state2 %>
			</html:link>
		  </TD>
        <%
        
        if(i+ sleftover+ssize*2 >= universitiescpy.size()){
      	  break;
        }
        tuple = (Vector)universitiescpy.get(i+ sleftover+ssize*2);
        String state3 = (String)tuple.get(0);
        %>
          <TD>    	  	
            <html:link action="/degreeLoc">
			<html:param name="stuState" value='<%= state3 %>'/> <%= state3 %>
			</html:link>
		  </TD>
    	  </TR>
        <%       

      } 
       out.println("<br>");
       

       
%>
</TABLE>
<%	  
   
    Vector<String> countriescpy =s.getCountries(path1);
    countriescpy.remove("United States");
    int csize = countriescpy.size()/3;
    int leftover = countriescpy.size()%3;

%>  
    <br>Other Countries:<br>    
	<TABLE BORDER CELLSPACING=1 CELLPADDING=5>
	<TR>
<%
    //print all the countries
    for(int i=0; i<countriescpy.size()/3+1; i++){
      if(i == leftover+csize){
      	 break;
      }
%>
	<TD>
	   <html:link action="/degreeLoc">
	   <html:param name="stuState" value='<%= countriescpy.get(i) %>'/> <%= countriescpy.get(i) %>
	   </html:link>
	</TD>
<%
      
      if(i+ leftover+csize == leftover+csize*2){
    	  break;
      }
      
 %>
	<TD>
	   <html:link action="/degreeLoc">
	   <html:param name="stuState" value='<%= countriescpy.get(i+ leftover+csize) %>'/> <%= countriescpy.get(i+ leftover+csize) %>
	   </html:link>
	</TD>
<%      
      if(i+ leftover+csize*2 >= countriescpy.size()){
    	  break;
      }
      
%>
    <TD>
	   <html:link action="/degreeUniv">
	   <html:param name="stuState" value='<%= countriescpy.get(i+ leftover+csize*2) %>'/> <%= countriescpy.get(i+ leftover+csize*2) %>
	   </html:link>    
    </TD>
	</TR>
<%      
    }
    out.println("<br>");
%>
</TABLE>

</body>
</html>